package study.cdc.debezium.support.connector;

import cn.hutool.core.io.resource.ResourceUtil;
import io.debezium.config.Configuration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Mysql Connector 配置
 * https://debezium.io/documentation/reference/1.5/connectors/mysql.html#mysql-connector-properties
 */
@Slf4j
@org.springframework.context.annotation.Configuration
public class MySQLConnectorConfig {

    private static final String CONFIG_FILE = "mysql-collector.properties";

    @Bean
    public Configuration config() {
        Properties props = new Properties();
        try (InputStream is = ResourceUtil.getStream(CONFIG_FILE)) {
            props.load(is);
        } catch (IOException ex) {
            throw new RuntimeException("load properties error!", ex);
        }
        return Configuration.from(props);
    }
}
